import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
const api = '/flow/task';
export const minePage = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/myProcess', params });
export const todoPage = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/todoList',
    params,
    timeout: -1,
  });
export const doPage = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/finishedList', params });

// 审核通过
export const complete = (params?: any) =>
  defHttp.post({ url: `${api}/complete`, params });
export const unpass = (params?: any) =>
  defHttp.post({ url: `${api}/unpass`, params });
// 驳回到流程起点
export const reject = (params?: any) =>
  defHttp.post({ url: `${api}/reject`, params });
export const claim = (taskId?: string) =>
  defHttp.post({ url: `${api}/claim/${taskId}` });
export const diagram = (procInsId?: string) =>
  defHttp.get({ url: `${api}/xml/${procInsId}` });

export const del = (ids: string[]) =>
  defHttp.post({ url: api + '/delete', params: ids });
export const exp = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: api + '/export', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
